var GameData = require('../module/GameData')();

cc.Class({
    extends: cc.Component,

    properties: {
        heroname: cc.Label,
        hero: cc.Sprite,
        sp1: cc.Sprite,
        sp2: cc.Sprite,
        itemID: 0,
        heroAtlas: cc.SpriteAtlas,
        titlename: null,
        price: 0
    },
    onLoad() {
        this.node.on('touchend', this.changebg, this);
    },
    changebg() {
        for (var a = 0; a < GameData.select_hero.heroItem.length; a++) {
            GameData.select_hero.heroItem[a].getChildByName("checkmark").active = false;
        }
        this.sp2.node.active = true;
        GameData.select_hero.hero.node.getComponent(cc.Sprite).spriteFrame = this.heroAtlas.getSpriteFrame("people" + this.itemID);
        GameData.select_hero.hero_name.string = this.titlename;

        GameData.select_hero.pageId = this.itemID;
        if (GameData.gameData.owned.indexOf(this.itemID) != -1) {
            /*这个英雄已拥有  判断是否装备这个英雄*/
            if (this.itemID == GameData.gameData.selectId) {
                GameData.select_hero.changebuyBg(0);
            } else {
                GameData.select_hero.changebuyBg(1);
            }
        } else {
            GameData.select_hero.hero_price.string = this.price;
            GameData.select_hero.changebuyBg(2);
        }
    },

    init: function (heroInfo) {
        this.heroname.string = heroInfo.name;
        this.titlename = heroInfo.name;
        this.itemID = heroInfo.id;
        this.hero.node.getComponent(cc.Sprite).spriteFrame = this.heroAtlas.getSpriteFrame("qiehuan_hero" + heroInfo.id);
        this.price = heroInfo.price;

        if (heroInfo.id == 1) {
            this.changebg();
        }

    },

    start() {

    },

    // update (dt) {},
});
